package com.leyou.item.service;

import com.leyou.item.mapper.SpecMapper;
import com.leyou.item.mapper.SpecParamMapper;
import com.leyou.item.pojo.SpecGroup;
import com.leyou.item.pojo.SpecParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: taft
 * @Date: 2018-12-20 10:53
 */
@Service
public class SpecService {

    @Autowired
    private SpecMapper specMapper;

    @Autowired
    private SpecParamMapper specParamMapper;

    public List<SpecGroup> querySpecGroups(Long cid) {

        SpecGroup specGroup = new SpecGroup();
        specGroup.setCid(cid);

        List<SpecGroup> specGroups = this.specMapper.select(specGroup);

        //查询完成规格参数组，要同时查询组内的参数
        specGroups.forEach(sg->{
            SpecParam specParam = new SpecParam();
            specParam.setGroupId(sg.getId());
            specParam.setCid(sg.getCid());
            sg.setSpecParams(this.specParamMapper.select(specParam));
        });
        return specGroups;
    }

    //根据组id查询组内所有的规格参数属性
    public List<SpecParam> querySpecParam(Long gid,Long cid,Boolean searching,Boolean generic) {

        SpecParam specParam = new SpecParam();
        specParam.setGroupId(gid);

        specParam.setCid(cid);

        specParam.setSearching(searching);

        specParam.setGeneric(generic);


        return this.specParamMapper.select(specParam);
    }
}
